package jumtsmon;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class umtsReader implements Runnable{
    public static String serialDevice;
           static BufferedReader bufferedReader;
    public static String modemOutput;


           umtsReader() throws FileNotFoundException {
                serialDevice = Main.SerialPort;
                bufferedReader = new BufferedReader(new FileReader(serialDevice));

    }

    public void run() {
        while(true) {
            try {
                readDeviceStream();
                Thread.sleep(10000);
            }
            catch (NullPointerException npe) {
            }
            catch (InterruptedException ex) {
                Logger.getLogger(umtsReader.class.getName()).log(Level.SEVERE, null, ex);
            }
            catch (IOException ex) {
                Logger.getLogger(umtsReader.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }


    private static void  readDeviceStream() throws IOException {
         modemOutput = "";
         String line = null;
         try {
            while( (line = bufferedReader.readLine() ) != null) {
                System.out.println(line);
                modemOutput += line;
            }

         }
         catch (FileNotFoundException ex) {
             ex.printStackTrace();
         }
         catch (IOException ex) {
             ex.printStackTrace();
         }
    }

    private static void closeDeviceFile() {
         try {
             if (bufferedReader != null)
                 bufferedReader.close();
         }
         catch (IOException ex) {
             ex.printStackTrace();
         }
    }
}
